  
    <div class="user_head_info">
    <div class="user_ava"> 
        <?php if(Yii::app()->user->getState('avatar')) : ?>
        <img src="/images/uploads/userAvatars/<?php echo Yii::app()->user->getState('avatar'); ?>" style="width:30px; height: 30px;"/>
        <?php else : ?>
        <img src="/images/prettyImg/default-avatarl.jpg" width="45px" alt="" />
        <?php endif; ?>
    </div>    
    <span class="profile_username"><?php echo Yii::app()->user->getState('displayName'); ?></span><br/>
   <span class="last_login">Последний раз был   <?php echo Yii::app()->dateFormatter->format("dd MMMM в HH:mm", Yii::app()->user->getState('logDate')); ?></span> 
  
</div>
<?php $this->renderPartial('//partials/userMenu', array('countNewComments'=>$this->countNewComments['count'], 'countNewMessages'=>$this->countNewMessages['count'],'curent'=>'messages')); ?>

<script>
    $(document).ready(
        function() {
            $('#showOrHideForm').click(function() {
                var display = $('#formContainer').css('display');
                if(display == 'none') {
                    $('#formContainer').slideDown(600);
                } else {
                    $('#formContainer').slideUp(600);
                }
            });
        }
    ); 
</script>


<div class="padding4020">
    
    <ul class="unstyled message_menu ">
    <li  class="selected"><a href="<?php echo Yii::app()->createUrl('user/messages/messages'); ?>">Входящие</a></li>
      <li><a class="" href="<?php echo Yii::app()->createUrl('user/messages/outbox'); ?>">Отправленные</a></li>
    <li><a class="" href="<?php echo Yii::app()->createUrl('user/messages/capt'); ?>">Корзина</a></li>
    </ul>
   
    <div class="clearfix"></div>
     <?php if(count($mesData)) : ?>
        <span class="pull-right mes_numbers"><?php echo count($mesData); ?> из <?php echo $pagination->getItemCount(); ?> сообщений</span>
    <?php endif; ?>
 <div class="dialog_head">
    
     <div class="user_ava" style="margin-top: 5px;"> 
         <?php 
            $userFrom;
            foreach ($users as $k=>$v) {
                if($v['userId'] != Yii::app()->user->getId()) 
                    $userFrom = $users[$k];
            } 
        ?>
        <?php if(!empty($userFrom) && $userFrom['avatar']) : ?>
            <img src="/images/uploads/userAvatars/<?php echo $userFrom['avatar']; ?>" style="width:30px; height: 30px;"/>
        <?php else : ?>
            <img src="/images/prettyImg/default-avatarl.jpg" width="45px" alt="" />
        <?php endif; ?>
    </div> 
      <?php if(!empty($userFrom)) : ?>
         <h2 class="profil_h2">
             Переписка с   <a  href="<?php echo Yii::app()->createUrl('user/profile/profile', array('login'=>$userFrom['login'])); ?>"><?php echo $userFrom['displayName']; ?></a>
         </h2>
      <?php endif; ?>
    </div>
     <div style="margin-bottom: 20px;height: 20px;margin-top: 15px;">
         <?php if(!empty($userFrom)) : ?>
            <span id="showOrHideForm" class="write_link pull-left">Ответить</span><span style="margin-left:30px;"  class="write_link pull-left">Удалить переписку</span>
         <?php endif; ?>    
    </div>
    <div class="clearfix"></div>
    
    <?php if(!empty($userFrom)) : ?>
     <div id="formContainer" style="display:none">
        <div class="forum_form_cut"></div>
        <div class="comment_form" style="margin-bottom: 30px;">
            <div style="width:100%;display: inline-block;"><span class="pull-right close_form" onclick="$('#formContainer').slideUp(600)"></span></div>
        <?php echo CHtml::errorSummary($model, 'Пожалуйста исправьте следующие ошибки:'); ?>

        <?php echo CHtml::beginForm('', 'post', array('id'=>'messageForm')); ?>

            
            
             <div class="pull-left">
              
                <?php echo CHtml::activeHiddenField($model, 'users', array('id'=>'usersTo', 'value'=>$companion)); ?>        
                            
                 <?php echo CHtml::activeLabel($model, 'message',array('style'=>'color:#898989;fomt-size:12px;')); ?>
        <?php echo CHtml::activeTextArea($model, 'message', array('class'=>'text_area_comm', 'id'=>'messagearea','style'=>'width:550px;')); ?>
                
                
    </div>    
        
    <div class="pull-left" style="margin-left: 23px;margin-top: 20px;">
    
           
       
      </div>  
            
        
        
  <div class="clearfix"></div> 
  
  <div style="height:40px;"></div>
            
            
    
                
         <?php echo CHtml::submitButton('Отправить', array('class'=>'bt_submit_review')); ?>

        <?php echo CHtml::endForm(); ?> 
    </div>
    </div>
    
    
    
    
    
    
    <?php endif; ?>
    
    <div class="dialog_list">
        
        <?php if(!empty($mesData)) : ?>
            <?php for ($i=0; $i<count($mesData);$i++) : ?>
                <div class="d_message <?php if($mesData[$i]['fromId'] == Yii::app()->user->getState('userid')) {  ?> my_mess   <?php  } ?>">
                    <div class="d_message_text"> <?php echo $mesData[$i]['message']; ?>  </div>
                    <div class="d_message_data">
                        <?php if($mesData[$i]['fromId']== Yii::app()->user->getState('userid')) {  ?>
                            <?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy в HH:mm", $mesData[$i]['sendDate']); ?>
                            <?php if($mesData[$i]['message'] != '<span style="color:gray">Сообщение было удалено</span>') : ?>
                                &nbsp;&nbsp;&nbsp; <a class="write_link" href="<?php echo Yii::app()->createUrl('user/messages/delMessage', array('id'=>$mesData[$i]['id'])); ?>">Удалить</a>  
                            <?php endif; ?>
                        <?php  } else { ?> 
                            <?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy в HH:mm", $mesData[$i]['sendDate']); ?>   
                        <?php  } ?> 
                    </div>
                </div>  

                <div class="clearfix"></div>
                <div style="height:20px;">&nbsp;</div>
            <?php endfor; ?>
        <?php endif; ?>    
    </div>
    
    <div class="pages"> <?php $this->widget('CLinkPager', array('pages' => $pagination)); ?> </div>
</div>